﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace QLFUI
{
    public partial class FormEx : FormBase
    {
        #region - 变量 -

        public enum FormStyle
        {
            QQ,
            XunLei,
            _360,
            Chrome,
            Customer
        }
        private FormStyle currentFormStyle = FormStyle.QQ;

        #endregion

        #region - 属性 -

        [Browsable(true), Description("皮肤样式"), Category("2_QLFUI_Other")]
        public FormStyle FormSkin
        {
            get { return currentFormStyle; }
            set
            {
                currentFormStyle = value;
                switch (currentFormStyle)
                {
                    case FormStyle.QQ:
                        #region QQ
                        //边框
                        BorderColor = Color.FromArgb(54, 107, 130);
                        InnerBorderColor = Color.FromArgb(136, 201, 227);
                        //标题栏
                        TitleBackColorStart = Color.FromArgb(101, 187, 220);
                        TitleBackColorEnd = Color.FromArgb(86, 175, 215);
                        TitleHeight = 35;


                        #region 右上角功能按钮

                        btnClose.Height = btnMax.Height = btnMin.Height = 25;
                        btnClose.Width = 25;
                        btnMax.Width = 25;
                        btnMin.Width = 25;
                        btnClose.AnimateSpeed = btnMin.AnimateSpeed = btnMax.AnimateSpeed = 100;
                        FunctionBtnMarginTop = 5;
                        FunctionBtnMarginRight = 8;

                        btnClose.BorderRadius.RightTop = 0;
                        btnClose.BorderRadius.RightBottom = 0;
                        btnMin.BorderRadius.LeftTop = 0;
                        btnMin.BorderRadius.LeftBottom = 0;

                        #region normal

                        btnClose.BorderColor = Color.Transparent;
                        btnMax.BorderColor = Color.Transparent;
                        btnMin.BorderColor = Color.Transparent;

                        btnClose.InnerBorderColor = Color.Transparent;
                        btnMax.InnerBorderColor = Color.Transparent;
                        btnMin.InnerBorderColor = Color.Transparent;

                        btnClose.BackColorStart
                           = btnMin.BackColorStart
                           = btnMax.BackColorStart
                           = Color.Transparent;

                        btnClose.BackColorEnd
                            = btnMin.BackColorEnd
                              = btnMax.BackColorEnd
                                = Color.Transparent;


                        #endregion

                        #region Hover

                        btnMax.BorderColorHover
                            = btnMin.BorderColorHover
                            = Color.Transparent;
                        btnClose.BorderColorHover = Color.Transparent;

                        btnMax.InnerBorderColorHover
                            = btnMin.InnerBorderColorHover
                            = Color.Transparent;
                        btnClose.InnerBorderColorHover = Color.Transparent;

                        btnMax.BackColorStartHover = Color.Transparent;
                        btnMin.BackColorStartHover = Color.Transparent;
                        btnMax.BackColorEndHover = Color.Transparent;
                        btnMin.BackColorEndHover = Color.Transparent;
                        btnClose.BackColorStartHover = Color.Transparent;
                        btnClose.BackColorEndHover = Color.Transparent;

                        #endregion

                        #region Press

                        btnMax.BorderColorPress
                            = btnMin.BorderColorPress
                            = Color.Transparent;
                        btnClose.BorderColorPress = Color.Transparent;

                        btnMax.InnerBorderColorPress
                            = btnMin.InnerBorderColorPress
                            = Color.Transparent;
                        btnClose.InnerBorderColorPress = Color.Transparent;

                        btnMax.BackColorStartPress = Color.Transparent;
                        btnMin.BackColorStartPress = Color.Transparent;
                        btnMax.BackColorEndPress = Color.Transparent;
                        btnMin.BackColorEndPress = Color.Transparent;
                        btnClose.BackColorStartPress = Color.Transparent;
                        btnClose.BackColorEndPress = Color.Transparent;

                        #endregion

                        #endregion


                        //内容
                        ContentBackColorStart = Color.FromArgb(245, 251, 253);
                        ContentBackColorEnd = Color.FromArgb(246, 251, 253);
                        ContentBottomBorderColor = Color.FromArgb(208, 218, 229);
                        ContentTopBorderColor = Color.FromArgb(208, 218, 229);

                        //底部
                        FooterBackColorStart = Color.FromArgb(220, 226, 234);
                        FooterBackColorEnd = Color.FromArgb(220, 226, 234);
                        FooterHeight = 32;

                        #endregion
                        break;

                    case FormStyle.Chrome:
                        #region chrome

                        //边框
                        BorderColor = Color.FromArgb(89, 89, 89);
                        InnerBorderColor = Color.FromArgb(133, 171, 228);
                        //标题栏
                        TitleBackColorStart = Color.FromArgb(98, 147, 221);
                        TitleBackColorEnd = Color.FromArgb(66, 113, 201);
                        TitleHeight = 35;

                        #region 右上角功能按钮

                        btnClose.Height = btnMax.Height = btnMin.Height = 20;
                        btnClose.Width = 43;
                        btnMax.Width = 25;
                        btnMin.Width = 27;
                        btnMin.BorderRadius.LeftBottom = 3;
                        if (ShowCloseButton)
                        {
                            btnClose.BorderRadius.RightBottom = 3;
                        }
                        btnClose.BorderRadius.RightTop = 0;
                        btnMin.BorderRadius.LeftTop = 0;

                        btnClose.AnimateSpeed = btnMin.AnimateSpeed = btnMax.AnimateSpeed = 100;


                        FunctionBtnMarginTop = 0;
                        FunctionBtnMarginRight = 8;


                        #region normal

                        btnClose.BorderColor = Color.FromArgb(55, 85, 131);
                        btnMax.BorderColor = Color.FromArgb(55, 85, 131);
                        btnMin.BorderColor = Color.FromArgb(55, 85, 131);

                        btnClose.InnerBorderColor = Color.FromArgb(139, 173, 228);
                        btnMax.InnerBorderColor = Color.FromArgb(139, 173, 228);
                        btnMin.InnerBorderColor = Color.FromArgb(139, 173, 228);

                        btnClose.BackColorStart
                           = btnMin.BackColorStart
                           = btnMax.BackColorStart
                           = Color.FromArgb(98, 147, 221);

                        btnClose.BackColorEnd
                            = btnMin.BackColorEnd
                              = btnMax.BackColorEnd
                                = Color.FromArgb(83, 132, 213);


                        #endregion

                        #region Hover

                        btnMax.BorderColorHover
                            = btnMin.BorderColorHover
                            = Color.FromArgb(52, 81, 128);
                        btnClose.BorderColorHover = Color.FromArgb(91, 53, 82);

                        btnMax.InnerBorderColorHover
                            = btnMin.InnerBorderColorHover
                            = Color.FromArgb(181, 203, 238);
                        btnClose.InnerBorderColorHover = Color.FromArgb(247, 161, 159);

                        btnMax.BackColorStartHover = Color.FromArgb(152, 184, 233);
                        btnMin.BackColorStartHover = Color.FromArgb(152, 184, 233);
                        btnMax.BackColorEndHover = Color.FromArgb(143, 174, 227);
                        btnMin.BackColorEndHover = Color.FromArgb(143, 174, 227);
                        btnClose.BackColorStartHover = Color.FromArgb(218, 84, 82);
                        btnClose.BackColorEndHover = Color.FromArgb(217, 70, 69);

                        #endregion

                        #region Press

                        btnMax.BorderColorPress
                            = btnMin.BorderColorPress
                            = Color.FromArgb(58, 87, 132);
                        btnClose.BorderColorPress = Color.FromArgb(49, 78, 126);

                        btnMax.InnerBorderColorPress
                            = btnMin.InnerBorderColorPress
                            = Color.FromArgb(140, 159, 188);
                        btnClose.InnerBorderColorPress = Color.FromArgb(183, 105, 107);

                        btnMax.BackColorStartPress = Color.FromArgb(143, 175, 224);
                        btnMin.BackColorStartPress = Color.FromArgb(134, 165, 218);
                        btnMax.BackColorEndPress = Color.FromArgb(143, 175, 224);
                        btnMin.BackColorEndPress = Color.FromArgb(134, 165, 218);
                        btnClose.BackColorStartPress = Color.FromArgb(215, 57, 61);
                        btnClose.BackColorEndPress = Color.FromArgb(213, 56, 60);

                        #endregion

                        #endregion


                        //内容
                        ContentBackColorStart = Color.White;
                        ContentBackColorEnd = Color.White;
                        ContentBottomBorderColor = Color.FromArgb(208, 218, 229);
                        ContentTopBorderColor = Color.FromArgb(208, 218, 229);

                        //底部
                        FooterBackColorStart = Color.FromArgb(223, 223, 223);
                        FooterBackColorEnd = Color.FromArgb(223, 223, 223);
                        FooterHeight = 2;

                        #endregion
                        break;

                    case FormStyle._360:
                        #region 360

                        //边框
                        BorderColor = Color.FromArgb(2, 38, 62);
                        InnerBorderColor = Color.FromArgb(66, 134, 180);
                        //标题栏
                        TitleBackColorStart = Color.FromArgb(20, 105, 162);
                        TitleBackColorEnd = Color.FromArgb(28, 149, 217);

                        #region 右上角功能按钮

                        btnClose.Height = btnMax.Height = btnMin.Height = 20;
                        btnClose.Width = 34;
                        btnMax.Width = 34;
                        btnMin.Width = 34;
                        btnMin.BorderRadius.LeftBottom = 3;
                        if (ShowCloseButton)
                        {
                            btnClose.BorderRadius.RightBottom = 3;
                            btnClose.BorderRadius.RightTop = 5;
                        }
                        btnClose.AnimateSpeed = btnMin.AnimateSpeed = btnMax.AnimateSpeed = 100;
                        FunctionBtnMarginTop = 0;
                        FunctionBtnMarginRight = 0;


                        #region normal

                        btnClose.BorderColor = Color.FromArgb(10, 80, 125);
                        btnMax.BorderColor = Color.FromArgb(10, 80, 125);
                        btnMin.BorderColor = Color.FromArgb(10, 80, 125);

                        btnClose.InnerBorderColor = Color.Transparent;
                        btnMax.InnerBorderColor = Color.Transparent;
                        btnMin.InnerBorderColor = Color.Transparent;

                        btnClose.BackColorStart
                           = btnMin.BackColorStart
                           = btnMax.BackColorStart
                           = Color.FromArgb(32, 113, 167);

                        btnClose.BackColorEnd
                            = btnMin.BackColorEnd
                              = btnMax.BackColorEnd
                                = Color.FromArgb(14, 108, 168);


                        #endregion

                        #region Hover

                        btnMax.BorderColorHover
                            = btnMin.BorderColorHover
                            = Color.FromArgb(10, 80, 125);
                        btnClose.BorderColorHover = Color.FromArgb(10, 80, 125);

                        btnMax.InnerBorderColorHover
                            = btnMin.InnerBorderColorHover
                              = Color.Transparent;
                        btnClose.InnerBorderColorHover = Color.FromArgb(163, 84, 85);

                        btnMax.BackColorStartHover = Color.FromArgb(65, 133, 179);
                        btnMin.BackColorStartHover = Color.FromArgb(65, 133, 179);
                        btnMax.BackColorEndHover = Color.FromArgb(18, 103, 159);
                        btnMin.BackColorEndHover = Color.FromArgb(18, 103, 159);
                        btnClose.BackColorStartHover = Color.FromArgb(145, 50, 52);
                        btnClose.BackColorEndHover = Color.FromArgb(85, 68, 93);

                        #endregion

                        #region Press

                        btnMax.BorderColorPress
                            = btnMin.BorderColorPress
                            = Color.FromArgb(13, 66, 100);
                        btnClose.BorderColorPress = Color.FromArgb(15, 50, 77);

                        btnMax.InnerBorderColorPress
                            = btnMin.InnerBorderColorPress
                              = Color.Transparent;
                        btnClose.InnerBorderColorPress = Color.Transparent;

                        btnMax.BackColorStartPress = Color.FromArgb(14, 73, 113);
                        btnMin.BackColorStartPress = Color.FromArgb(14, 73, 113);
                        btnMax.BackColorEndPress = Color.FromArgb(16, 81, 123);
                        btnMin.BackColorEndPress = Color.FromArgb(16, 81, 123);
                        btnClose.BackColorStartPress = Color.FromArgb(20, 69, 107);
                        btnClose.BackColorEndPress = Color.FromArgb(48, 55, 83);

                        #endregion

                        #endregion


                        //内容
                        ContentBackColorStart = Color.White;
                        ContentBackColorEnd = Color.White;
                        ContentBottomBorderColor = Color.FromArgb(17, 106, 158);
                        ContentTopBorderColor = Color.FromArgb(17, 106, 158);

                        //底部
                        FooterBackColorStart = Color.FromArgb(21, 131, 196);
                        FooterBackColorEnd = Color.FromArgb(12, 110, 172);
                        FooterHeight = 28;

                        #endregion
                        break;

                }
                Invalidate();
            }
        }

        #endregion

        #region - 构造函数 -

        public FormEx()
        {
            InitializeComponent();
        }

        #endregion

        #region - 事件 -

        protected override void OnPaint(PaintEventArgs e)
        {
            //开启透明效果时候，在设计视图下
            //Onpaint仍然需要触发，以便看到实际效果
            Draw(e.Graphics);

            base.OnPaint(e);
        }
        
        #endregion

        #region -辅助函数-

        protected override void Draw(Graphics g)
        {
            g.InterpolationMode = InterpolationMode.High;
            g.SmoothingMode = SmoothingMode.HighQuality;

            //Matrix s = new Matrix(1, 0.1f, 0, 1, 0.3f, 0);
            //Matrix currentMatrix = new Matrix();
            //currentMatrix.Multiply(s);
            //g.Transform = currentMatrix;

            //清除所有的图像
            if (EnableTransparent)
            {
                g.Clear(Color.Transparent);
            }

            #region 背景

            //画标题栏
            DrawBackground(g, new Rectangle(TitleRectangle.X + 1, TitleRectangle.Y + 1, TitleRectangle.Width - 3, TitleRectangle.Height - 1), TitleBackColorStart, TitleBackColorEnd,
                           new BorderRadiu(BorderRadius.LeftTop, BorderRadius.RightTop, 0, 0));

            //画主窗体
            DrawBackground(g, new Rectangle(ContentRectangle.X + 1, ContentRectangle.Y, ContentRectangle.Width - 3, ContentRectangle.Height), ContentBackColorStart, ContentBackColorEnd,
                           new BorderRadiu(0, 0, 0, 0));

            //画底部
            DrawBackground(g, new Rectangle(FooterRectangle.X + 1, FooterRectangle.Y, FooterRectangle.Width - 3, FooterRectangle.Height - 1), FooterBackColorStart, FooterBackColorEnd,
                           new BorderRadiu(0, 0, BorderRadius.RightBottom, BorderRadius.LeftBottom));

            #endregion

            #region 外边框

            using (var pen = new Pen(BorderColor))  /*边框永远不会透明*/
            {
                g.DrawPath(pen, DrawRoundRect(ClientRectangle.X,
                                              ClientRectangle.Y,
                                              ClientRectangle.Width - 1,
                                              ClientRectangle.Height - 1, BorderRadius.LeftTop,
                                              BorderRadius.RightTop, BorderRadius.RightBottom,
                                              BorderRadius.LeftBottom));
            }

            #endregion

            #region 内边框

            using (var pen = new Pen(InnerBorderColor))  /*边框永远不会透明*/
            {
                g.DrawPath(pen, DrawRoundRect(ClientRectangle.X + 1,
                                              ClientRectangle.Y + 1,
                                              ClientRectangle.Width - 3,
                                              ClientRectangle.Height - 3, BorderRadius.LeftTop,
                                              BorderRadius.RightTop, BorderRadius.RightBottom,
                                              BorderRadius.LeftBottom));
            }

            #endregion

            #region 绘制标题和LOGO

            //绘制标题
            if (!string.IsNullOrEmpty(Text))
            {
                g.DrawString(Text, Font, new SolidBrush(ForeColor),
                             ShowIcon ? new Point(26, 10) : new Point(10, 10));
            }

            //绘制图标
            if (ShowIcon)
            {
                g.DrawIcon(Icon, new Rectangle(6, 8, 18, 18));
            }

            #endregion

            g.DrawString(ClientRectangle.ToString(), Font, new SolidBrush(Color.Red), new PointF(100, 100));

            base.Draw(g);
        }

        //protected void fangzhuang()
        //{

        //    Bitmap b = (Bitmap)currentBitmap.Clone();
        //    if (currentBitmap != null)
        //    {
        //        currentBitmap.Dispose();
        //    }
        //    currentBitmap = new Bitmap(Width + 200, Height + 200, PixelFormat.Format32bppArgb);

        //    SetBitmap(currentBitmap, 0);


        //    float i = 0;
        //    Graphics g = GetNewGraphics;
        //    Timer timer = new Timer();
        //    timer.Tick += delegate
        //                      {


        //                              g.Clear(Color.Transparent);
        //                              Matrix s = new Matrix(1, i, 0, 1, 0.3f, 0);
        //                              Matrix currentMatrix = new Matrix();
        //                              currentMatrix.Multiply(s);
        //                              g.Transform = currentMatrix;

        //                              g.DrawImage(b, 0, 0);
        //                              SetBitmap(b, 255);

        //                              i += 0.05f;

        //                              if (i >= 0.6f)
        //                              {
        //                                  timer.Stop();
        //                              }

        //                      };
        //    timer.Interval = 1000;
        //    timer.Start();


        //    //Draw();

        //}

        #endregion
    }
}